<template>
  <el-dialog
    title='amazon-comment'
    size="large"
    class="login-form "
    width="440px"
    :close-on-click-modal="false"
    :destroy-on-close="true"
    :lock-scroll="false"
    :visible="visible"
    :before-close="handleClose">
    <div class="second_block">
      <br>
      <div style="font-size: 15px;text-align: center;color: white;">{{script_1}}</div>
      <br>
      <div style="text-align: center">
        <el-input
          type="textarea"
          :placeholder="char"
          maxlength="1000"
          size="10"
          rows="4"
          v-model="form.comment"
          show-word-limit
        >
        </el-input>
      </div>
      <br>
      <div style="font-size: 15px;text-align: center;color: white;">{{script_2}}</div>
      <br>
      <div style="text-align: center">
        <el-button type="warning" @click="doConfirmGiftPage" >{{script_3}}</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>

export default {
  name: "amazon-comment",
  props: {
    // 弹窗是否打开
    visible: Boolean,
    data: Object,
  },
  data() {
    return {
      // 表单数据
      form: Object.assign({}, this.data),
      // 表单验证规则
      rules: {
      },
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      char:'',
      char_length:0,
      script_1:'',
      script_2:'',
      script_3:'',
      comment_sensitive_word:[],
      sensitive_word_no:0,
    };
  },
  methods : {
    //关闭页面
    handleClose(done) {
      done();
      this.$emit('handleClose');
    },
    setBuyerConfig(data){
      this.script_1 = data.amazon_comment_page_script.script_1;
      this.script_2 = data.amazon_comment_page_script.script_2;
      this.script_3 = data.amazon_comment_page_script.script_3;
      this.char_length = data.comment_mini_char;
      this.comment_sensitive_word = data.comment_sensitive_word;
      this.sensitive_word_no = data.sensitive_word_no;
      this.char = 'Please enter at least '+data.comment_mini_char+' characters';
    },
    //跳转确认礼品页面
    doConfirmGiftPage()
    {

      //判断是否有填写评价
      if (!this.form.comment){
        this.$message({type:'warning',message:'请填写评价',offset:160});
      }else if (this.form.comment.length < this.char_length){
        this.$message({type:'warning',message:'评价少于最少字符长度'+this.char_length+'个字符',offset:160});
      }else{
        //留评敏感词过滤
        var info=this.form.comment.split(' ');
        var comment_new = [];
        var sensitive_word = [];//评论中是否有敏感词
        info.forEach(item => {
          if (this.comment_sensitive_word.indexOf(item) === -1) comment_new.push(item);
          if (this.comment_sensitive_word.indexOf(item) !== -1) sensitive_word.push(item);
        })
        this.form.comment = comment_new.join(' ')
        this.$copyText(this.form.comment).then(function (e) {
          console.log(e)
        }, function (e) {
          console.log(e)
        });
        if (sensitive_word.length>0 && this.sensitive_word_no==1){
          this.$message({type:'warning',message:'评论中有敏感词:'+ sensitive_word.join(' ; ') + '不引导amazon留评' ,offset:160,duration:4000});
          this.form.sensitive_user = 1;
          setTimeout(() => {
            this.$emit('getConfirmGiftPage',this.form)
          }, 5000);
        }else {
          window.open('https://bbs.zhmj.com/forum.php?mod=viewthread&tid=157', '_blank');
          this.$emit('getConfirmGiftPage',this.form);
        }

      }

    }
  }
}
</script>

<style scoped>

::v-deep .el-rate__icon{
  font-size: 30px;
}

</style>
